﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class CX_XMGLJGControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        CustomGridView CustomGridList1;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            if (!Page.IsPostBack)
            {
                Bind();

            }
            Button CX = (Button)FindControl("CX");
            CX.Click += new EventHandler(CX_Click);
            CustomGridList1.OnLoadData += new EventHandler(CustomGridList1_OnLoadData);
        }

        protected void CX_Click(object sender, EventArgs e)
        {
            Bind();
        }

        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            Bind();
        }
        public void Bind()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            TextBox XMName = (TextBox)FindControl("XMName");
            TextBox 立项号 = (TextBox)FindControl("立项号");
            string where = string.Empty;
            if (!string.IsNullOrEmpty(XMName.Text.Trim()))
            {
                where += " and z.项目名称 like '%" + XMName.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(立项号.Text.Trim()))
            {
                where += " and z.立项号 like '%" + 立项号.Text.Trim() + "%'";
            }
            string sqlrole = "Select rolename From zs_role  Where Id In (Select roleid  From zs_user_in_role Where userid = '" + userid + "') and rolename like '%征收部门%'";
            DataTable dtrole = _EluZSDataProvider.GetTable(sqlrole);
            string role = string.Empty;
            if (dtrole.Rows.Count>0)
            {
                role = dtrole.Rows[0]["rolename"].ToString();
                string rolestr = role.Substring(0, 2);
                where += " and z.区属 like '%" + rolestr + "%'";
            }
            string sql = @"Select id,立项号,项目名称 From zs_project z where 1=1 " + where;
            sql += " order by addtime desc ";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            CustomGridList1.DataSource = dt;
            CustomGridList1.RecordCount = dt.Rows.Count;
            CustomGridList1.PageSize = 10;
            CustomGridList1.DataBind();
        }

        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView rowview = (DataRowView)e.Row.DataItem;
                string strId = rowview["ID"].ToString();
                Literal 立项审批 = (Literal)e.Row.FindControl("立项审批");
                Literal 冻结审批 = (Literal)e.Row.FindControl("冻结审批");
                Literal 补偿方案审批 = (Literal)e.Row.FindControl("补偿方案审批");
                Literal 资金开户审批 = (Literal)e.Row.FindControl("资金开户审批");
                Literal 房源审批 = (Literal)e.Row.FindControl("房源审批");
                Literal 风险评估报告 = (Literal)e.Row.FindControl("风险评估报告");
                Literal 补偿实施方案审批 = (Literal)e.Row.FindControl("补偿实施方案审批");
                Literal 征收决定审批 = (Literal)e.Row.FindControl("征收决定审批");

                立项审批.Text = _EluZSDataProvider.GetString(@"select (Case 
          When 
            (Select Count(*) From zs_project Where id = '" + strId + @"' And 审批状态 =1 ) >0
          Then 
          '√'
          Else
          '  '
          End ) from dual ");
                冻结审批.Text = _EluZSDataProvider.GetString(@"select (Case 
          When 
            (Select Count(*) From zs_project Where id= '" + strId + @"' And 冻结审批状态 =1 ) >0
          Then 
          '√'
          Else
          '  '
          End ) from dual ");
                补偿方案审批.Text = _EluZSDataProvider.GetString(@"select (Case 
          When 
            (Select Count(*) From zs_project Where id= '" + strId + @"' And 补偿审批状态 =1 ) >0
          Then 
          '√'
          Else
          '  '
          End ) from dual ");
                资金开户审批.Text = _EluZSDataProvider.GetString(@"Select Case When (Select Count(Id) From ZS_BCBASICINFO Where 开户审核状态=3 And pnid='" + strId + @"')>0 Then '√' Else '  ' End From dual  ");
                房源审批.Text = _EluZSDataProvider.GetString(@"Select Case When (Select Count(Id) From zs_proloupan Where pid='" + strId + @"')>0 Then '√' When (Select Count(Id) From zs_project Where id='" + strId + @"' and 房源说明备注 is not null)>0 Then '√' Else '  ' End From dual");
                风险评估报告.Text = _EluZSDataProvider.GetString(@"Select Case When (Select Count(Id) From zs_file Where use_type=7 And itemname='风险评估报告' And itemid='" + strId + @"')>0 Then '√' Else '  ' End From dual ");
                补偿实施方案审批.Text = _EluZSDataProvider.GetString(@"select (Case 
          When 
            (Select Count(*) From zs_project Where id= '" + strId + @"' And 补偿实施审批状态 =1 ) >0
          Then 
          '√'
          Else
          '  '
          End ) from dual ");
                征收决定审批.Text = _EluZSDataProvider.GetString(@"select (Case 
          When 
            (Select Count(Distinct Id) From zs_file Where itemname='公告与征收决定' And itemid='" + strId + @"') >0
          Then 
          '√'
          Else
          '  '
          End ) from dual ");
                
            }
        }


    }
}
